package 老师;

import GUI.*;
import 数据库和网络.myDatebase;

import java.sql.SQLException;

public class teacher {
    private String name,schoolID,password;

    public teacher(){}

    public void teacherLog(String ID,String password){
        myDatebase LogConfirm = new myDatebase("teacher");
        String sql = "select teacherID,teacherPassword from teacher.teacher";
        try {
            LogConfirm.statement.execute(sql);
            LogConfirm.resultSet = LogConfirm.statement.executeQuery(sql);
            boolean isRight = false;
            while (LogConfirm.resultSet.next()) {
                if (ID.equals(LogConfirm.resultSet.getString(1)) && password.equals(LogConfirm.resultSet.getString(2))) {
                    isRight = true;
                    new teacherWindow("a");
                    new successfulLog("a");

                }
            }
            if (!isRight) {
                new incorrectLog();
            }
            LogConfirm.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    public static void teacherRegister(String preID,String prePassword){
        enterWindow.identity="老师";
        boolean isNew=true;
        myDatebase registerConfirm=new myDatebase("teacher");
        String sql="select 'teacherID','teacherPassWord' from teacher.teacher";
        try {
            registerConfirm.statement.execute(sql);
            registerConfirm.resultSet=registerConfirm.statement.executeQuery(sql);
            while(registerConfirm.resultSet.next()){
                if(preID.equals(registerConfirm.resultSet.getString(1))){
                    isNew=false;
                    new incorrectRegister();
                }
            }
            if(isNew){
                sql="insert teacher.teacher ( teacherID, teacherPassword) values ('"+preID+"','"+prePassword+"')";
                registerConfirm.statement.execute(sql);
                new successfulRegister();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    void correction(){}

    void browseGrades(){}

    void browsePapers(){}

    void makePaper(){}

    void browseQuestions(){}

    void editQuestions(){}

    void checkStudents(){}

    public String getName(){
        return name;
    }

    public String getSchoolID(){
        return schoolID;
    }

    public String getPassword(){
        return password;
    }

    public String setName(String a){
        name=a;
        return name;
    }

    public String setSchoolID(String a){
        schoolID=a;
        return schoolID;
    }


    String setPassword(String a){
        password=a;
        return password;
    }
}
